package org.example._05_delay;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * 延时消息:用于类似点餐,点击支付,但是却未支付并取消了,而一段时间内,库存不会立马释放,过了一段时间后检查才做业务
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("rocketmq-producer");
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        defaultMQProducer.start();
        Message message = new Message(
                "05-delay",
                "hello,rocketmq".getBytes()
        );
        //设置延迟级别,每种级别代表不同时间
        message.setDelayTimeLevel(2);
        SendResult sendResult = defaultMQProducer.send(message);
        System.out.println(sendResult.getMsgId());//没输出表示失败了
        defaultMQProducer.shutdown();
    }
}